﻿/*
 * @author: wizardc
 */

using Dou.UI;
using UnityEditor;
using UnityEditor.UI;
using UnityEngine;
using UnityEngine.UI;

namespace DouEditor.UI
{
    [CustomEditor(typeof(DImage), true)]
    [CanEditMultipleObjects]
    public class DImageEditor : ImageEditor
    {
        [MenuItem("GameObject/DouUI/Image", false, 10)]
        private static void CreateUI(MenuCommand menuCommand)
        {
            var go = UIEditorUtil.CreateUIElement("Image");
            var img = go.AddComponent<DImage>();
            img.sprite = null;
            img.color = Color.white;
            img.type = Image.Type.Sliced;
            img.raycastTarget = false;
            UIEditorUtil.PlaceUIElementRoot(go, menuCommand);
        }

        public override void OnInspectorGUI()
        {
            var image = (DImage) target;
            using (new GUILayout.VerticalScope())
            {
                image.useGray = EditorGUILayout.Toggle(new GUIContent("置灰"), image.useGray);
                image.useNativeSize = EditorGUILayout.Toggle(new GUIContent("使用原始尺寸"), image.useNativeSize);
            }
            base.OnInspectorGUI();
        }
    }
}
